<!DOCTYPE html>
{% load static %}
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>老师信息</title>
    <style>
        #container {
            width: 80%;
        }
        .teacher {
            width: 100%;
            margin: 0 auto;
            padding: 10px 0;
            border-bottom: 1px dashed gray;
            overflow: auto;
        }
        .teacher div {
            float: left;
        }
        .photo {
            height: 140px;
            border-radius: 75px;
            overflow: hidden;
            margin-left: 20px;
        }
        .info {
            width: 75%;
            margin-left: 30px;
        }
        .info div {
            clear: both;
            margin: 5px 10px;
        }
        .info span {
            margin-right: 25px;
        }
        .info a {
            text-decoration: none;
            color: blue;
        }
        .user {
            float: right;
            margin: 10px 10px;
        }
        .user+h1 {
            clear: both;
        }
        #photo {
            border-radius: 32px 32px 32px 32px;
        }
    </style>
</head>
<body>
    {% include 'header.html' %}
    <h1>{{ subject.name }}的老师信息</h1>
    <hr>
    <div id="container">
        {% for teacher in teachers %}
        <div class="teacher">
            <div class="photo">
                <img src="{% static teacher.photo %}" height="140" alt="">
            </div>
            <div class="info">
                <div>
                    <span><strong>姓名：{{ teacher.name }}</strong></span>
                    <span>性别：{{ teacher.gender | yesno:'男,女' }}</span>
                    <span>出生日期：{{ teacher.birth }}</span>
                </div>
                <div class="intro">{{ teacher.intro }}</div>
                <div class="comment">
                    <a href="/vote/praise/?tno={{ teacher.no }}">好评</a>（<span>{{ teacher.good_count }}</span>）
                    <a href="/vote/criticize/?tno={{ teacher.no }}">差评</a>（<span>{{ teacher.bad_count }}</span>）
                </div>
            </div>
        </div>
        {% endfor %}
    </div>
    <script src="{% static 'js/jquery.min.js' %}"></script>
    <script>
        $(() => {
            $('.comment > a').on('click', (evt) => {
                evt.preventDefault()
                let a = $(evt.target)
                $.ajax({
                    url: a.attr('href'),
                    type: 'get',
                    data: {},
                    dataType: 'json',
                    success: (json) => {
                        if (json.code == 200) {
                            let span = a.next()
                            span.text(parseInt(span.text()) + 1)
                        } else if (json.code == 401) {
                            location.href = '/vote/login/?backurl=' +
                                location.pathname + location.search
                        } else {
                            alert(json.message)
                        }
                    }
                })
            })
        })
    </script>
</body>
</html>